﻿<?xml version="1.0" encoding="UTF-8" ?>
<sqlMap namespace="ibatisnet" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <cacheModels>
    <cacheModel id="resource_cache"  implementation="MEMORY" >
      <flushInterval hours="24"/>
      <flushOnExecute  statement="ResourceLogic_ClearResourceList"/>
      <flushOnExecute  statement="ResourceLogic_Insert"/>
      <flushOnExecute  statement="ResourceLogic_Update"/>
      <flushOnExecute  statement="ResourceLogic_Delete"/>
      <property name="Type" value="Weak"/>
    </cacheModel>
  </cacheModels>
  
  <statements>
    <select id="ResourceLogic_GetResourceList" resultClass="Portal.Entity.ResourceEntity" cacheModel="resource_cache">
        SELECT RESOURCEID
        ,CNNAME
        ,ENNAME
        ,TYPE
        ,MODULE
        ,CODE
        ,PARENTID
        ,REMARK
        ,ORDERNO
        ,ISACTIVE
        ,CREATEDATE
        ,CREATEBY
        ,UPDATEDATE
        ,UPDATEBY
        ,EFFECTFROM
        ,EFFECTTO
        ,EXT01
        ,EXT02
        ,EXT03
        ,EXT04
        ,EXT05
        ,EXT06
        ,EXT07
        ,EXT08
        ,EXT09
        ,EXT10
        ,EXT11
        ,EXT12
        ,EXT13
        ,EXT14
        ,EXT15
        ,EXT16
        ,EXT17
        ,EXT18
        ,EXT19
        ,EXT20
        ,EXT21
        ,EXT22
        ,EXT23
        ,EXT24
        ,EXT25
        ,EXT26
        ,EXT27
        ,EXT28
        ,EXT29
        ,EXT30
        FROM COM_Resource
        WHERE ISACTIVE=1
        ORDER BY MODULE,ORDERNO
    </select>

    <insert id="ResourceLogic_Insert" parameterClass="Portal.Entity.ResourceEntity" >
      INSERT INTO COM_Resource
      (
      RESOURCEID
      ,CNNAME
      ,ENNAME
      ,TYPE
      ,MODULE
      ,CODE
      ,PARENTID
      ,REMARK
      ,ORDERNO
      ,ISACTIVE
      ,CREATEDATE
      ,CREATEBY
      ,UPDATEDATE
      ,UPDATEBY
      ,EFFECTFROM
      ,EFFECTTO
      ,EXT01
      ,EXT02
      ,EXT03
      ,EXT04
      ,EXT05
      ,EXT06
      ,EXT07
      ,EXT08
      ,EXT09
      ,EXT10
      ,EXT11
      ,EXT12
      ,EXT13
      ,EXT14
      ,EXT15
      ,EXT16
      ,EXT17
      ,EXT18
      ,EXT19
      ,EXT20
      ,EXT21
      ,EXT22
      ,EXT23
      ,EXT24
      ,EXT25
      ,EXT26
      ,EXT27
      ,EXT28
      ,EXT29
      ,EXT30
      )
      VALUES(
      #RESOURCEID#
      ,#CNNAME#
      ,#ENNAME#
      ,#TYPE#
      ,#MODULE#
      ,#CODE#
      ,#PARENTID#
      ,#REMARK#
      ,#ORDERNO#
      ,#ISACTIVE#
      ,#CREATEDATE#
      ,#CREATEBY#
      ,#UPDATEDATE#
      ,#UPDATEBY#
      ,#EFFECTFROM#
      ,#EFFECTTO#
      ,#EXT01#
      ,#EXT02#
      ,#EXT03#
      ,#EXT04#
      ,#EXT05#
      ,#EXT06#
      ,#EXT07#
      ,#EXT08#
      ,#EXT09#
      ,#EXT10#
      ,#EXT11#
      ,#EXT12#
      ,#EXT13#
      ,#EXT14#
      ,#EXT15#
      ,#EXT16#
      ,#EXT17#
      ,#EXT18#
      ,#EXT19#
      ,#EXT20#
      ,#EXT21#
      ,#EXT22#
      ,#EXT23#
      ,#EXT24#
      ,#EXT25#
      ,#EXT26#
      ,#EXT27#
      ,#EXT28#
      ,#EXT29#
      ,#EXT30#
      )
    </insert>

    <update id="ResourceLogic_Update" parameterClass="Portal.Entity.ResourceEntity" >
      UPDATE COM_RESOURCE SET
      CNNAME=#CNNAME#
      ,ENNAME=#ENNAME#
      ,TYPE=#TYPE#
      ,MODULE=#MODULE#
      ,CODE=#CODE#
      ,PARENTID=#PARENTID#
      ,REMARK=#REMARK#
      ,ORDERNO=#ORDERNO#
      ,ISACTIVE=#ISACTIVE#
      ,CREATEDATE=#CREATEDATE#
      ,CREATEBY=#CREATEBY#
      ,UPDATEDATE=#UPDATEDATE#
      ,UPDATEBY=#UPDATEBY#
      ,EFFECTFROM=#EFFECTFROM#
      ,EFFECTTO=#EFFECTTO#
      ,EXT01=#EXT01#
      ,EXT02=#EXT02#
      ,EXT03=#EXT03#
      ,EXT04=#EXT04#
      ,EXT05=#EXT05#
      ,EXT06=#EXT06#
      ,EXT07=#EXT07#
      ,EXT08=#EXT08#
      ,EXT09=#EXT09#
      ,EXT10=#EXT10#
      ,EXT11=#EXT11#
      ,EXT12=#EXT12#
      ,EXT13=#EXT13#
      ,EXT14=#EXT14#
      ,EXT15=#EXT15#
      ,EXT16=#EXT16#
      ,EXT17=#EXT17#
      ,EXT18=#EXT18#
      ,EXT19=#EXT19#
      ,EXT20=#EXT20#
      ,EXT21=#EXT21#
      ,EXT22=#EXT22#
      ,EXT23=#EXT23#
      ,EXT24=#EXT24#
      ,EXT25=#EXT25#
      ,EXT26=#EXT26#
      ,EXT27=#EXT27#
      ,EXT28=#EXT28#
      ,EXT29=#EXT29#
      ,EXT30=#EXT30#
      WHERE RESOURCEID=#RESOURCEID#
    </update>

    <delete id="ResourceLogic_Delete">
      DELETE FROM COM_RESOURCE WHERE RESOURCEID=#RESOURCEID#;
      DELETE FROM COM_RESOURCERELATION WHERE SOURCEID=#SOURCEID#;
    </delete>
    
    <select id="ResourceLogic_Exist" >
      SELECT COUNT(1) FROM COM_RESOURCE WHERE RESOURCEID=#RESOURCEID#
    </select>
    
    <select id="ResourceLogic_ClearResourceList" >
      SELECT 1
    </select>

    <insert id="ResourceRelationLogic_Save" parameterClass="Portal.Entity.ResourceRelationEntity" >
     INSERT INTO COM_ResourceRelation
      (
      ID
      ,SOURCEID
      ,DESTINATIONID
      ,RELATIONTYPE
      ,CREATEDATE
      ,CREATEBY
      ,EXT01
      ,EXT02
      ,EXT03
      ,EXT04
      ,EXT05
      ,EXT06
      ,EXT07
      ,EXT08
      ,EXT09
      ,EXT10
      ,EXT11
      ,EXT12
      ,EXT13
      ,EXT14
      ,EXT15
      ,EXT16
      ,EXT17
      ,EXT18
      ,EXT19
      ,EXT20
      ,EXT21
      ,EXT22
      ,EXT23
      ,EXT24
      ,EXT25
      ,EXT26
      ,EXT27
      ,EXT28
      ,EXT29
      ,EXT30
      )
      VALUES(
      #ID#
      ,#SOURCEID#
      ,#DESTINATIONID#
      ,#RELATIONTYPE#
      ,#CREATEDATE#
      ,#CREATEBY#
      ,#EXT01#
      ,#EXT02#
      ,#EXT03#
      ,#EXT04#
      ,#EXT05#
      ,#EXT06#
      ,#EXT07#
      ,#EXT08#
      ,#EXT09#
      ,#EXT10#
      ,#EXT11#
      ,#EXT12#
      ,#EXT13#
      ,#EXT14#
      ,#EXT15#
      ,#EXT16#
      ,#EXT17#
      ,#EXT18#
      ,#EXT19#
      ,#EXT20#
      ,#EXT21#
      ,#EXT22#
      ,#EXT23#
      ,#EXT24#
      ,#EXT25#
      ,#EXT26#
      ,#EXT27#
      ,#EXT28#
      ,#EXT29#
      ,#EXT30#
      )
    </insert>

    <select id="ResourceRelationLogic_GetList" resultClass="Portal.Entity.ResourceRelationEntity" >
      SELECT
      ID
      ,SOURCEID
      ,DESTINATIONID
      ,RELATIONTYPE
      ,CREATEDATE
      ,CREATEBY
      ,EXT01
      ,EXT02
      ,EXT03
      ,EXT04
      ,EXT05
      ,EXT06
      ,EXT07
      ,EXT08
      ,EXT09
      ,EXT10
      ,EXT11
      ,EXT12
      ,EXT13
      ,EXT14
      ,EXT15
      ,EXT16
      ,EXT17
      ,EXT18
      ,EXT19
      ,EXT20
      ,EXT21
      ,EXT22
      ,EXT23
      ,EXT24
      ,EXT25
      ,EXT26
      ,EXT27
      ,EXT28
      ,EXT29
      ,EXT30
      FROM COM_RESOURCERELATION
      WHERE SOURCEID=#SOURCEID#
      
    </select>
    
    <delete id="ResourceRelationLogic_Delete" >
      DELETE FROM COM_RESOURCERELATION WHERE SOURCEID=#SOURCEID# AND (EXT01='Menu' OR EXT01=#SECURITYTYPE# OR RelationType='SecurityMember')
    </delete>

    <select id="SecurityLogic_GetSecurityList" resultClass="Portal.Entity.ResourceRelationEntity">
      SELECT b.*
      FROM COM_RESOURCERELATION a
      INNER JOIN COM_RESOURCERELATION b on a.SOURCEID=b.SOURCEID
      where a.DESTINATIONID=#userId# and a.RELATIONTYPE='SecurityMember' and a.EXT01='User'
      and b.RELATIONTYPE='SecurityObject'
    </select>
    
  </statements>
</sqlMap>